package com.spic.business.contractorsync.controller;

import com.spic.business.contractorsync.domain.ContractorPerson;
import com.spic.business.contractorsync.service.IContractorPersonService;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 供应商人员同步Controller
 *
 * @author spic
 * @date 2022-06-05
 */
@RestController
@RequestMapping("/person")
public class ContractorPersonController extends BaseController {
    @Autowired
    private IContractorPersonService contractorPersonService;

    /**
     * 查询供应商人员同步列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ContractorPerson contractorPerson) {
        startPage();
        List<ContractorPerson> list = contractorPersonService.selectContractorPersonList(contractorPerson);
        return getDataTable(list);
    }


    /**
     * 获取供应商人员同步详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(contractorPersonService.selectContractorPersonById(id));
    }

    /**
     * 新增供应商人员同步
     */
    @PostMapping
    public AjaxResult add(@Validated @RequestBody List<ContractorPerson> list) {
        return AjaxResult.success(contractorPersonService.insertContractorPerson(list));
    }

    /**
     * 修改供应商人员同步
     */
    @Log(title = "供应商人员同步", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ContractorPerson contractorPerson) {
        return toAjax(contractorPersonService.updateContractorPerson(contractorPerson));
    }

    /**
     * 删除供应商人员同步
     */
    @Log(title = "供应商人员同步", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(contractorPersonService.deleteContractorPersonByIds(ids));
    }
}
